<?php
class ContactformsController extends AppController
{
	var $name = "Contactforms";
	
	function send()
	{
		$this->Contactform->set($this->data);
		if($this->Contactform->validates()) {
			$mailBody  = "Naam: {$this->data['Contactform']['name']}\r\n";
			$mailBody .= "Email: {$this->data['Contactform']['email']}\r\n";
			$mailBody .= "Telefoonnr: {$this->data['Contactform']['phone']}\r\n\n";
			$mailBody .= "Bericht: {$this->data['Contactform']['body']}\r\n";
			
			$headers  = "MIME-Version: 1.0 \r\n";
			$headers .= "Content-Type: text/plain; charset=\"utf-8\" \r\n";
			$headers .= "From: {$this->data['Contactform']['name']} <{$this->data['Contactform']['email']}>" . "\r\n";

			mail(
				"geert1@gmail.com",
				"Contact formulier website",
				$mailBody,
				$headers
			);
			$this->Session->setFlash('Bericht verstuurd.');
			$this->redirect($this->referer());
		}
		else {
			$this->Session->setFlash('Niet alle velden zijn goed ingevuld.');
			$this->redirect($this->referer());
		}
	}
}
?>